﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpMUD.Framework.Net
{
    /// <summary>
    /// Defines functionality for anything that sits and listens for INetworkConnection's
    /// </summary>
    public interface INetworkConnectionListener
    {
        /// <summary>
        /// The local IP endpoint that the connection listener is listening on
        /// </summary>
        System.Net.IPEndPoint ListenPoint { get; }
        
        /// <summary>
        /// The array of connections that have been attempted, but not recognized yet
        /// </summary>
		IEnumerable<INetworkConnection> PendingConnections { get; }
        
        /// <summary>
        /// Removes a waiting connection from the list of attempted connections
        /// </summary>
        /// <param name="value">The connection to remove</param>
        void RemoveWaitingConnection(INetworkConnection value, bool accepted);

        /// <summary>
        /// This event is raised when a connection attempt is made
        /// </summary>
        event ConnectionListenerEventHandler ConnectionAttempted;

        event ConnectionListenerEventHandler ConnectionAccepted;

        event ConnectionListenerEventHandler ConnectionRejected;

        /// <summary>
        /// Tells the connection listener to start listening for connections
        /// </summary>
        void Start();
        /// <summary>
        /// Tells the connection listener to stop listening for connections
        /// </summary>
        void Stop();
    }

    /// <summary>
    /// The signature of a method that can handle an event raised by an IConnectionListener
    /// </summary>
    public delegate void ConnectionListenerEventHandler(INetworkConnectionListener sender, INetworkConnection connection);
}
